home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 2 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: news.rmii.com!usenet
  2. From: jcoffin@rmii.com (Jerry Coffin)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Statements, sequence points and execution order
  5. Date: Mon, 01 Jan 1996 03:09:06 GMT
  6. Organization: TAEUS
  7. Message-ID: <4c7ffq$p8j@natasha.rmii.com>
  8. References: <4c45oc$1sc8@pulp.ucs.ualberta.ca>
  9. NNTP-Posting-Host: slip8158.rmii.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. wiecek@ee.ualberta.ca (B. Wiecek) wrote:
  13.  
  14. >As far as I remeber (see above) the standard requires that statements
  15. >are executed in the same order they are written, thus if I write:
  16.  
  17. >    a = 1;        /* statement1 */
  18. >    b = a + 1;    /* statement2 */
  19. >    c = 3;        /* statement3 */
  20. >    d = c + 1;    /* statement4 */
  21.  
  22. >the standard requires that these statements shall be executed in this order,
  23. >right?
  24.  
  25. As long as a, b, c and d are all non-volatile, it can reorder as it
  26. wishes, as long as there's no way of telling the difference.  If they're
  27. all non-volatile, the compiler is free to produce something like:
  28.  
  29.     a=1;
  30.     b=2;
  31.     c=3;
  32.     d=4;
  33.  
  34. and execute them all simultaneously on a 4+ processor machine.  Or, if
  35. these are static, and haven't been previously used, it could treat it
  36. all as initialized data, with no actual execution involved at all.
  37.  
  38. >However, today's suprscalar processors (eg. Alpha) and compilers for them
  39. >may/will reorder the above to something like:
  40.  
  41. >    a = 1;        /* statement1 */
  42. >    c = 3;        /* statement3 */
  43. >    b = a + 1;    /* statement2 */
  44. >    d = c + 1;    /* statement4 */
  45.  
  46. >Does the standard allow this?
  47.  
  48. It all depends on whether any or all of a, b, c or d is volatile or not.
  49. With volatile variables, the value of each variable must be correct at
  50. each sequence point, and it's required to actually read/write the memory
  51. location to obtain/store the value.  E.g. even if the value of a is in a
  52. register after setting a in statement 1, it's still required to read the
  53. value from memory when it executes statement 2.  Likewise with the value
  54. of c in statement 3 & 4.
  55.     Later,
  56.     Jerry.
  57.  
  58. /* I can barely express my own opinions; I certainly can't
  59.  * express anybody else's.
  60.  *
  61.  * The universe is a figment of its own imagination.
  62.  */
  63.  
  64.